package com.leetcode.problems;

/**
 * @version: 1.0
 * @author: Vpen
 * @date: 2021/12/11 17:49
 * @content: 反转链表  1->2->3  1<-2<-3
 */
public class Problem2 {
    public static void main(String[] args) {
        ListNode header = new ListNode(1);
        ListNode node1 = new ListNode(2);
        ListNode node2 = new ListNode(3);
        ListNode node3 = new ListNode(4);
        ListNode node4 = new ListNode(5);
        header.next = node1;
        node1.next = node2;
        node2.next = node3;
        node4.next = null;

        Solution2_1 solution21 = new Solution2_1();
        System.out.println(solution21.reverseList(header));
        System.out.println(node4);


    }

}

/**
 * @author:韦鹏
 * @desc: 
 * */
class Solution2_1 {
    public ListNode reverseList(ListNode head) {
        ListNode newHead = null;
        while (head != null) {
            ListNode temp = head.next;
            head.next = newHead;
            newHead = head;
            head = temp;
        }
        return newHead;
    }
}